package cn.tedu.basic;
//测试字符串拼接
import sun.util.locale.provider.DateFormatProviderImpl;

import java.lang.reflect.Method;

public class Test1 {
    public static void main(String[] args) {
        Method();//用 + 拼接
        Method2();//用工具拼接
        Method3();
        Method1();
        Method5();
        Method6();
    }
    public static void Method(){
        String s="niubvnfovgjnbo";
        long start =System.currentTimeMillis();
        String s1 =" ";
        for (int i = 0; i <10000 ; i++) {
            s1=s1 + s;
        }
        long end =System.currentTimeMillis();
        System.out.println(end-start);
    }
        //用工具拼接--StringBuilder
        public static void Method2(){
        String s2="vgrhbgerhrht";
        StringBuilder sb =new StringBuilder();
        long start =System.currentTimeMillis();
            for (int i = 0; i <10000 ; i++) {
                //调用方法
                sb.append(s2);
            }
            long end =System.currentTimeMillis();
            System.out.println(end-start);
        }
        //StringBuffer
        public  static void Method3(){
        String s3="hfhvdhfod";
        StringBuffer sbf =new StringBuffer();
        long start =System.currentTimeMillis();
            for (int i = 0; i <10000 ; i++) {
                sbf.append(s3);
            }
            long end =System.currentTimeMillis();
            System.out.println(end - start);
        }
        public static void Method1(){
        String s4 ="fdnvvnvf";
        String s5 ="";
        long start =System.currentTimeMillis();
            for (int i = 0; i <=10000 ; i++) {
                s5=s5+s4;
            }
            long end =System.currentTimeMillis();
            System.out.println(end - start );
        }
        public  static void Method5(){
        String s6="uiefiubg";
        StringBuffer sbr =new StringBuffer();
        long start =System.currentTimeMillis();
            for (int i = 0; i <=10000 ; i++) {
                sbr.append(s6);
            }
            long end =System.currentTimeMillis();
            System.out.println(end-start);
        }
        public static void Method6(){
        String s7="sdnhnsoivn";
        StringBuilder sbd =new StringBuilder();
        long start =System.currentTimeMillis();
            for (int i = 0; i <=10000 ; i++) {
                sbd.append(s7);
            }
            long end =System.currentTimeMillis();
            System.out.println(end -start);
        }




















}
